IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[InsertLinea]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[InsertLinea]
GO

CREATE PROCEDURE [dbo].[InsertLinea]
(
	@IdLinea int OUT,
	@Nombre varchar(255),
	@Descripcion text,
	@Imagen varchar(150)
)
AS
BEGIN
	SET NOCOUNT ON

	INSERT INTO [Linea] ([Nombre], [Descripcion], [Imagen]) 
	VALUES (@Nombre, @Descripcion, @Imagen)

	SET @IdLinea = SCOPE_IDENTITY()

	IF @imagen <> ''
    BEGIN
		UPDATE [Linea] SET [Imagen] = REPLACE(@imagen, '{0}', CONVERT(varchar, @idLinea)) WHERE [IdLinea] = @idLinea
    END

	SET NOCOUNT OFF
END

GO
